package grape.attend.rest.user.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.attend.rest.user.form.UserVacationSumCreateForm;
import grape.attend.rest.user.form.UserVacationSumUpdateForm;
import grape.attend.rest.user.form.UserVacationSumListPageForm;
import grape.attend.rest.user.vo.UserVacationSumVo;
import grape.attend.rest.user.mapper.UserVacationSumWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.attend.service.user.po.UserVacationSum;
import grape.attend.service.user.api.IUserVacationSumService;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
/**
 * <p>
 * 用户假期余额表 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-05-18
 */
@RestController
@RequestMapping("/attend/uservacationsum")
@Api(tags = "用户假期余额相关接口")
public class UserVacationSumController extends BaseController<UserVacationSumVo, UserVacationSum> {

    @Autowired
    private UserVacationSumWebMapper currentWebMapper;
    @Autowired
    private IUserVacationSumService currentService;



     @ApiOperation("添加用户假期余额")
     @PreAuthorize("hasAuthority('uservacationsum:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public UserVacationSumVo create(@RequestBody @Valid UserVacationSumCreateForm cf) {
         UserVacationSum po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询用户假期余额")
     @PreAuthorize("hasAuthority('uservacationsum:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public UserVacationSumVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除用户假期余额")
     @PreAuthorize("hasAuthority('uservacationsum:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新用户假期余额")
     @PreAuthorize("hasAuthority('uservacationsum:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public UserVacationSumVo update(@PathVariable String id,@RequestBody @Valid UserVacationSumUpdateForm uf) {
         UserVacationSum po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("分页查询用户假期余额")
    @PreAuthorize("hasAuthority('uservacationsum:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<UserVacationSumVo> listPage(UserVacationSumListPageForm listPageForm) {
         UserVacationSum po = currentWebMapper.formToPo(listPageForm);
         return super.listPage(po,listPageForm);
     }


    @ApiOperation("查询当前登录用户假期余额")
    @PreAuthorize("hasAuthority('uservacationsum:single:myList')")
    @GetMapping("/my/list")
    @ResponseStatus(HttpStatus.OK)
    public List<UserVacationSumVo> myListPage(@ApiIgnore String loginUserId) {
        UserVacationSum po = new UserVacationSum();
        po.setUserId(loginUserId);
        return super.list(po);
    }
}
